<template>
	<el-dialog title="修改管理员" :visible.sync="dialogVisible" width="40%">
		<el-form ref="form" label-width="80px" :model="form">
			<el-form-item label="账号">
				<el-input placeholder="" v-model="form.account"></el-input>
			</el-form-item>

			<el-form-item label="性别">
				<el-col :span="9"><el-radio v-model="form.gender" label="男">男</el-radio>
					<el-radio v-model="form.gender" label="女">女</el-radio></el-button> </el-col>

			</el-form-item>
			<el-form-item label="电话">
				<el-input placeholder="" v-model="form.phone"></el-input>
			</el-form-item>
			<el-form-item label="地址">
				<el-input placeholder="" v-model="form.address"></el-input>
			</el-form-item>
			<el-form-item label="角色">
					<el-col :span="15">
							<el-checkbox v-model="form.roles" v-for="role in roleList" :label="role.id":key="role.id">
							{{role.name}}
							</el-checkbox>
					</el-col>

			</el-form-item>

		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button @click="dialogVisible = false">取 消</el-button>
			<el-button type="primary" @click="save()">保存</el-button>
		</span>
	</el-dialog>
</template>

<script>
	export default {
		name: "Add",
		data() {
			return {
				dialogVisible: false,
				roleList: [],
				form: {},
			}
		},
		methods: {
			findAdminById(id){
				this.$http.get("admin/AdminCtl/findAdminById?id="+id).then((resp) => {
					this.form=resp.data.data;
				})
			},
			save() {
				this.$http.post("admin/AdminCtl/saveAdmin", this.form).then((resp) => {
					if(resp.data.code==200){
						this.$message({
							showClose: true,
							message: '恭喜你，修改成功✔',
							type: 'success'
						});
						this.$router.go();
					}
				})
			}
		},
		mounted() {
			this.$http.get("admin/AdminCtl/findRoles").then((res) => {
				if (res.data.code == 200) {
					this.roleList = res.data.data;
				}
			})
		}
	}
</script>